import time

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()# 实例化浏览器驱动
driver.implicitly_wait(10)
driver.maximize_window()#窗口最大化
def crud():#添加
    #输入地址
     driver.get('http://10.10.10.120:30209')
    #输入账号密码
     driver.find_element(By.ID,'username').send_keys('administrator')
     driver.find_element(By.ID,'password').send_keys('Gdjt@2021')
     driver.find_element(By.XPATH,'//button').click()
     time.sleep(5)
 #进入菜单
     driver.find_element(By.XPATH, '//*[text()="物料数据管理"]').click()
     driver.find_element(By.XPATH, '//*[text()="物资分类"]').click()
     time.sleep(2)


  #添加父级节点
     driver.find_element(By.XPATH,'//*[@id="root"]/section/section/section/main/div/div[1]/div/div/div[1]/i').click()
   # driver.find_element(By.XPATH, '/html/body/div[3]/div/div/div/div[2]/div/div/div/a[1]').click()


     name = "警报"
     driver.find_element(By.XPATH, '//*[@id="snameClass"]').send_keys('name')
     driver.find_element(By.XPATH, '//*[@id="scodeClass"]').send_keys('jb-01')
     driver.find_element(By.XPATH, '//*[@id="snameAs"]').send_keys(name)
     driver.find_element(By.XPATH, '//*[@id="snote"]').send_keys(name)
     driver.find_element(By.XPATH, '//*[text()="保 存"]/..').click()
     time.sleep(3)


    #添加同级节点
     select_element = driver.find_element(By.CSS_SELECTOR, '.anticon.anticon-ellipsis')
# 创建鼠标对象
     action = ActionChains(driver)#实例化一个模拟键盘操作的对象
# 调用鼠标悬停事件方法
     action.move_to_element(select_element).perform()


     driver.find_element(By.LINK_TEXT, "添加同级节点").click()
     driver.find_element(By.CSS_SELECTOR, ".ant-modal-body > .ant-spin-nested-loading").click()
     driver.find_element(By.ID, "snameClass").click()
     driver.find_element(By.ID, "snameClass").send_keys("2")
     driver.find_element(By.ID, "scodeClass").click()
     driver.find_element(By.ID, "scodeClass").send_keys("2")
     driver.find_element(By.ID, "snameAs").click()
     driver.find_element(By.ID, "snameAs").send_keys("2")
     driver.find_element(By.ID, "snote").click()
     driver.find_element(By.ID, "snote").send_keys("2")
     driver.find_element(By.CSS_SELECTOR, ".ant-btn-primary").click()

     #添加子节点
     select_element = driver.find_element(By.CSS_SELECTOR, '.anticon.anticon-ellipsis')
# 创建鼠标对象
     action = ActionChains(driver)  # 实例化一个模拟键盘操作的对象
# 调用鼠标悬停事件方法
     action.move_to_element(select_element).perform()
     driver.find_element(By.LINK_TEXT, "添加子节点").click()
     driver.find_element(By.CSS_SELECTOR, ".ant-modal-body > .ant-spin-nested-loading").click()
     driver.find_element(By.ID, "snameClass").click()
     driver.find_element(By.ID, "snameClass").send_keys("3")
     driver.find_element(By.ID, "scodeClass").click()
     driver.find_element(By.ID, "scodeClass").send_keys("3")
     driver.find_element(By.ID, "snameAs").click()
     driver.find_element(By.ID, "snameAs").send_keys("3")
     driver.find_element(By.ID, "snote").click()
     driver.find_element(By.ID, "snote").send_keys("3")
     driver.find_element(By.CSS_SELECTOR, ".ant-btn-primary").click()

    # 修改节点
#
     select_element = driver.find_element(By.CSS_SELECTOR, '.anticon.anticon-ellipsis')
# 创建鼠标对象
     action = ActionChains(driver)  # 实例化一个模拟键盘操作的对象
# 调用鼠标悬停事件方法
     action.move_to_element(select_element).perform()
     driver.find_element(By.LINK_TEXT, "修改节点").click()
     driver.find_element(By.XPATH,'//textarea[@placeholder="请输入备注"]').clear()
     driver.find_element(By.XPATH,'//textarea[@placeholder="请输入备注"]').send_keys('警报01')
     driver.find_element(By.XPATH, '//*[text()="保 存"]/..').click()
    #删除节点
     select_element = driver.find_element(By.XPATH, '(//i[@aria-label="图标: ellipsis"])[29]')
# 创建鼠标对象
     action = ActionChains(driver)  # 实例化一个模拟键盘操作的对象
# 调用鼠标悬停事件方法
     action.move_to_element(select_element).perform()
     driver.find_element(By.LINK_TEXT, "删除节点").click()
     driver.find_element(By.XPATH, '//*[text()="确 定"]/.').click()
if __name__ == '__main__':
     crud()
     time.sleep(5)
